import java.util.*;

public class Main {

    //
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        boolean[] hash = new boolean[10];

        for(int i = s.length - 1; i >= 0; i--){
            int x = s[i] - '0';
            if(!hash[x]){
                System.out.print(x);
                hash[x] = true;
            }
        }
    }

    //
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        PriorityQueue<Long> heap = new PriorityQueue<>();
        while(n-- != 0){
            long x = in.nextLong();
            heap.offer(x);
        }

        long ret = 0;
        while(heap.size() > 1){
            long t1 = heap.poll();
            long t2 = heap.poll();
            heap.offer(t1 + t2);
            ret += t1 + t2;
        }
        System.out.println(ret);
    }

    //
    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        char[] s = in.next().toCharArray();

        long[] f = new long[26];
        long[] g = new long[26];

        long ret = 0;
        for(int i = 0; i < n; i++){
            int x = s[i] - 'a';
            ret += f[x];

            //更新哈希表
            f[x] = f[x] + i - g[x];
            g[x] = g[x] + 1;
        }
        System.out.println(ret);
    }
}
